package org.jerrymouse.jsa4j.db.kv.mem;

import java.util.Map;

import org.jerrymouse.jsa4j.db.kv.DB;

public class MemDB implements DB {
	Map<String, String> cache;

	public void setCache(Map<String, String> cache) {
		this.cache = cache;
	}

	@Override
	public String get(String key) {
		return cache.get(key);
	}

	@Override
	public String put(String key, String value) {
		String valueOrg = null;
		if (key == null)
			return null;
		else {
			valueOrg = cache.get(key);
			if (valueOrg != null) {
				if (value == null) {
					cache.remove(key);
				} else {
					cache.put(key, value);
				}
			} else if (value != null) {
				cache.put(key, value);
			}
		}
		return key;
	}

}
